Quick sort using ‘c’                                            

Inclusion sort is a basic arranging calculation that works by building an arranged sublist each component in turn. It keeps a to some degree arranged cluster and emphasizes through the unsorted part, taking every component and embedding it into the right situation in the arranged sublist.


Here is the bit by bit course of the inclusion sort calculation:


1. Begin with the subsequent component (file 1) and consider it as the "key".


2. Contrast the key and the component before it (past component) and in the event that the key is more modest, push the past component one situation forward.


3. Rehash stage 2 for all components before the key while the key is more modest than them.


4. Embed the key into the right position found in the past QuickSort is a generally utilized arranging calculation that follows the separation and-overcome worldview. It works by choosing a turn component from the exhibit and parceling different components into two sub-clusters, as indicated by whether they are not exactly or more prominent than the turn. The sub-exhibits are then recursively arranged. Here is an outline of the QuickSort calculation:


1. Pick a turn component from the exhibit. This should be possible in various ways, for example, choosing the main component, the last component, or an irregular component.


2. Segment the exhibit by reworking its components with the end goal that all components not exactly the turn precede the turn, and all components more prominent than the turn come after the turn. After this dividing, the turn component is in its last arranged position.


3. Recursively apply stages 1 and 2 to the sub-exhibit of components before the turn (i.e., the components not exactly the turn) and the sub-cluster of components after the turn (i.e., the components more prominent than the turn).


4. The base instance of the recursion is the point at which the sub-exhibit has zero or one component, in which case it is now considered sorted.steps.


5. Move to the following component and rehash stages 2-4 until all components are arranged.

Program:-

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

    int a[50],num,x,y,temp,i,j,n;

    printf("no of elements  u want ");

    scanf("%d",&n);

    printf("enter the values");

    for(i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

 

    }

    qs(a,0,n-1);

    printf("sorted array is");

    for(i=0;i<n;i++)

        printf("%d\t",a[i]);

return 0;

 

}

 

int qs(int a[],int first,int last)

{

    int i,j,p,temp,n;

 

        p=first;

        i=first;

        j=last;

    while(i<j)

    {

        while((a[i]<=a[p])&&(i<last))

            i++;

        while(a[j]>a[p])

            j--;

        if(i<j)

        {

            temp=a[i];

            a[i]=a[j];

            a[j]=temp;

        }

 

    temp=a[p];

    a[p]=a[j];

    a[j]=temp;

    qs(a,first,j-1);

    qs(a,j+1,last);

    }

}

Output:-